import Vue from 'vue'
import dayjs from 'dayjs'
import { handleImage, handleScreenWidthToVw, handleScreenHeightToVh } from '@/utils/tools.js'

Vue.filter('dateTimeFormatter', (dateTime, format = 'YYYY-MM-DD HH:mm:ss') => {
  if (dateTime) {
    return dayjs(dateTime).format(format)
  }
  return ''
})

Vue.filter('dateTimeOnly', (dateTime, format = 'YYYY-MM-DD') => {
  if (dateTime) {
    return dayjs(dateTime).format(format)
  }
  return ''
})


// 图片资源全局过滤器
Vue.filter('imageFormat', handleImage)

Vue.filter('pxToVwFormat', (value) => {
  return handleScreenWidthToVw(value) + 'px'
})

Vue.filter('pxToVhFormat', (value) => {
  return handleScreenHeightToVh(value) + 'px'
})
